package com.cxmx.escort.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cxmx.escort.entity.BedOrder;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 充值表 Mapper 接口
 * </p>
 *
 * @author 陈云轩
 * @since 2019-10-21
 */
public interface BedOrderMapper extends BaseMapper<BedOrder> {

    @Select("SELECT " +
            "c.*  " +
            "FROM " +
            "es_region a " +
            "LEFT JOIN es_bed b ON a.id = b.hospital_id and b.delete_flag=0 " +
            "left join es_bed_order c on b.id=c.bed_id and c.delete_flag=0 " +
            "${ew.customSqlSegment}")
    IPage<BedOrder> pageOrder(Page<BedOrder> page, @Param(Constants.WRAPPER) QueryWrapper<BedOrder> qw);

    @Select("SELECT " +
            "sum(c.price) " +
            "FROM " +
            "es_region a " +
            "LEFT JOIN es_bed b ON a.id = b.hospital_id and b.delete_flag=0  "+
            "left join es_bed_order c on b.id=c.bed_id and c.delete_flag=0 " +
            "${ew.customSqlSegment}")
    Double countPrice(@Param(Constants.WRAPPER)QueryWrapper<BedOrder> qw);
}
